package com.cskaoyan.config;

import com.cskaoyan.interceptor.HandlerInterceptor1;
import com.cskaoyan.interceptor.HandlerInterceptor2;
import com.cskaoyan.interceptor.HandlerInterceptor3;
import com.cskaoyan.interceptor.HandlerInterceptor4;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * mvc:annotation-driven → @EnableWebMvc
 * 后续要配置一些其他的功能 → WebMvcConfigurer
 * @author stone
 * @date 2022/10/08 09:53
 */
@ComponentScan("com.cskaoyan.controller")
@EnableWebMvc
public class WebConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 也可以把HandlerInterceptor1注册为容器中的组件，通过@Autowired给它从容器中取出
        registry.addInterceptor(new HandlerInterceptor1()).addPathPatterns("/hello/**");
        registry.addInterceptor(new HandlerInterceptor2());//.addPathPatterns("/**");
        registry.addInterceptor(new HandlerInterceptor3()).addPathPatterns("/goodbye/**");
        registry.addInterceptor(new HandlerInterceptor4());
    }
}
